package com.sunrise.gateway.commons.watermark;

import java.awt.*;
import java.util.Comparator;

/**
 * Created by wangmin on 2018/3/22.
 */
public class WatermarkParam {
    public String text;     // 水印文字， 如：中国证券网
    public String fontName; //  字体名称，    如：方正黑体
    public int fontStyle;   // 字体样式，如：粗体和斜体(Font.BOLD|Font.ITALIC)
    public int fontSize;    // 字体大小，单位为像素
    public Color color;     // 字体颜色
    public int offsetX;   // 水印文字距离目标图片右侧的偏移量
    public int offsetY;  // 水印文字距离目标图片下侧的偏移量
    public float alpha; // 透明度(0.0 -- 1.0, 0.0为完全透明，1.0为完全不透明)

    public int textWidth;   // 不是传入参数, 内部计算出的文字长度
    public int printX;      // 不是传入参数, 内部计算出的打印在图片的具体X位置
    public int printY;      // 不是传入参数, 内部计算出的打印在图片的具体Y位置

    public WatermarkParam() {
    }
    public WatermarkParam(WatermarkParam cloneObject) {
        this.text = cloneObject.text;
        this.fontName = cloneObject.fontName;
        this.fontStyle = cloneObject.fontStyle;
        this.fontSize = cloneObject.fontSize;
        this.color = cloneObject.color;
        this.offsetX = cloneObject.offsetX;
        this.offsetY = cloneObject.offsetY;
        this.alpha = cloneObject.alpha;
        this.printX = cloneObject.printX;
        this.printY = cloneObject.printY;
    }

    public WatermarkParam(String text, String fontName, Integer fontStyle, Integer fontSize, Color color, int x, int y, Float alpha) {
        this.text = text;
        if (null != fontName)
            this.fontName = fontName;
        else
            this.fontName = "方正黑体";
        if (null != fontStyle)
            this.fontStyle = fontStyle;
        else
            this.fontStyle = Font.PLAIN;
        if (null != fontSize)
            this.fontSize = fontSize;
        else
            this.fontSize = 20;
        if (null != color)
            this.color = color;
        else
            this.color = Color.RED;
        this.offsetX = x;
        this.offsetY = y;
        if (null != alpha)
            this.alpha = alpha;
        else
            this.alpha = 1.0F;
    }
}

// 按照offsetToBottom属性从小到大排列
class WatermarkParamComparatorY implements Comparator<WatermarkParam> {
    @Override
    public int compare(WatermarkParam o1, WatermarkParam o2) {
        return o1.offsetY - o2.offsetY;
    }

    static public final WatermarkParamComparatorY watermarkParamComparatorY = new WatermarkParamComparatorY();
}
